<?php                                                                                                                                                                     
namespace Deployer;    
require 'recipe/common.php';

// Configuration  
set('ssh_type', 'native');
set('ssh_multiplexing', true);

// 密码验证，还有公钥私钥的方式，大家自行学习
//set('repository', 'https://wizardhan:password@git.oschina.net/wizardhan/my_lumen.git'); 
set('repository', 'https://git.oschina.net/wizardhan/my_lumen.git'); 
set('shared_files', ['.env']);   
set('shared_dirs', ['storage']);  
//set('writable_dirs', []); 

// Servers    
server('production_1', '120.132.20.61')  
->user('www-data')   
->password('pw123456')  // deployer 4.0好像不支持密码了，只能配rsa
->port(10010)
->set('deploy_path', '/data/htdocs/www')
->stage('prod'); // 标识该服务器类型，用于服务器分组

// Tasks   
//desc('Restart PHP-FPM service');  
//task('php-fpm:restart', function () {     
    // The user must have rights for restart service  
    // /etc/sudoers: username ALL=NOPASSWD:/bin/systemctl restart php-fpm.service  
//    run('sudo systemctl restart php-fpm.service');
//}); 

//after('deploy:symlink', 'php-fpm:restart');  
desc('Deploy your project');   

task('deploy', [
    'deploy:prepare',    
    'deploy:lock',      
    'deploy:release',
    'deploy:update_code',
    'deploy:shared',
    'deploy:writable',
    'deploy:vendors',
    'deploy:clear_paths',
    'deploy:symlink',
    'deploy:unlock',
    'cleanup',
    'success'
]);

after('deploy:failed', 'deploy:unlock');